package app.imttf.offline.backing.login;

import app.imttf.offline.adfextensions.ADFUtils;


//import java.util.HashMap;
import java.util.HashMap;
import java.util.Map;

import oracle.adf.view.rich.component.rich.input.RichInputText;

import oracle.adf.view.rich.context.AdfFacesContext;

import oracle.binding.OperationBinding;

public class LoginBean {

    private RichInputText inputLogin, inputPassword;
    private String _action;

    public String loginAction() {

        _action = null;

        OperationBinding login = ADFUtils.findOperation("authenticateUser");
        Map m = (Map)login.execute();

        try {
            if (m != null && !m.isEmpty()) {

                HashMap userAccess = (HashMap)m.get("UserAccess");
                String userNameLogin = (String)m.get("UserName");
                String fullName = (String)m.get("FullName");
                String kodeDc = (String)m.get("KodeDc");
                String userCompany = (String)m.get("Company");
                
                AdfFacesContext adfFacesContext = AdfFacesContext.getCurrentInstance();
                Map<String,Object> pageFlowScope = adfFacesContext.getPageFlowScope();
                pageFlowScope.put("userName", userNameLogin); 
                pageFlowScope.put("fullName", fullName); 
                pageFlowScope.put("kodeDc", kodeDc); 
                pageFlowScope.put("company", userCompany); 
                
                _action = "success";
            } else {
                _action = "errlogin";
            }
        } catch (Exception e) {
            _action = "errglobal";
        }

        return _action;
    }

    public void setInputLogin(RichInputText inputLogin) {
        this.inputLogin = inputLogin;
    }

    public RichInputText getInputLogin() {
        return inputLogin;
    }

    public void setInputPassword(RichInputText inputPassword) {
        this.inputPassword = inputPassword;
    }

    public RichInputText getInputPassword() {
        return inputPassword;
    }

}